package ooad.nextgen.gof.composite;

import ooad.nextgen.domain.Money;
import ooad.nextgen.domain.Sale;
import ooad.nextgen.gof.strategy.AbsoluteDiscountOverThresholdPricingStrategy;
import ooad.nextgen.gof.strategy.ISalePricingStrategy;
import ooad.nextgen.gof.strategy.PercentDiscountPricingStrategy;
/**
 * 多重折扣叠加。
 * 如满1000减200和9折优惠叠加，即(1000-200)*0.9 =720
 */
public class CompositeBestForCustomerPricingStrategy extends CompositePricingStrategy {
	public CompositeBestForCustomerPricingStrategy(){
		strategies.add(new AbsoluteDiscountOverThresholdPricingStrategy());
		strategies.add(new PercentDiscountPricingStrategy());	
	}
	@Override
	public Money getTotal(Sale sale) {
		Money lowestTotal = new Money(Integer.MAX_VALUE);
		for(ISalePricingStrategy strategy:strategies){
			Money total = strategy.getTotal(sale);
			lowestTotal = total.min(lowestTotal);
		}
		return lowestTotal;
	}

}
